package com.wushi.lenovo.asia5b.app_di.voucher.presenter;

import com.mvp.base.BasePresenter;
import com.mvp.base.model.ResultModel;
import com.mvp.common.LocalManageUtil;
import com.wushi.lenovo.asia5b.app_di.voucher.mvpview.VoucherFragmentView;
import com.wushi.lenovo.asia5b.app_http.ApiService;
import com.wushi.lenovo.asia5b.app_model.other.UserInfo;
import com.wushi.lenovo.asia5b.app_model.voucher.VoucherModel;
import com.wushi.lenovo.asia5b.app_model.voucher.VoucherType;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.Observable;

/**
 * Created by zhangyuncai on 2019/1/8.
 */
public class VoucherFragmentPresenter extends BasePresenter<VoucherFragmentView> {

    ApiService apiService;

    @Inject
    public VoucherFragmentPresenter(ApiService apiService) {
        this.apiService = apiService;
    }

    public void getVouchers(VoucherType voucherType) {
        Observable<ResultModel<List<VoucherModel>>> observable = null;

        if (voucherType == VoucherType.expired) {
            observable = apiService.getVoucherExpired(UserInfo.getMemberId(), LocalManageUtil.getAppLanguage());
        } else if (voucherType == VoucherType.used) {
            observable = apiService.getVoucherUsed(UserInfo.getMemberId(), LocalManageUtil.getAppLanguage());
        } else {
            observable = apiService.getVoucherUnused(UserInfo.getMemberId(), LocalManageUtil.getAppLanguage());
        }
        baseSubscribe(
                observable
                , resultModel -> {
                    getView().getVouchersResult(resultModel, voucherType);
                });
    }

}